﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Curchy.MetablogCMS.Models;
using Curchy.MetablogCMS.Persistance;

namespace Curchy.MetablogCMS.Controllers
{
    [HandleError]
    public class PageController : Controller
    {
        public ActionResult View(string slug)
        {
            if (string.IsNullOrEmpty(slug))
                slug = "/";

            Page p = MetablogPersistance.GetPage(slug);
            if (p != default(Page))
                return View(p);
            else
                throw new HttpException(404, "Not Found");
        }

        public ActionResult Media(string uid)
        {
            Guid key = new Guid(uid);
            var media = MetablogPersistance.GetMedium(key);
            return new ImageResult(media.Content, media.Type);
        }
    }
}
